package com.csgc.camera.widget.mask

import android.content.Context
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.csgc.camera.constants.MaskConfig
import com.cysd.spsyxj.R

class MaskKaoQin: MaskBase {



    constructor(context: Context?,id:Int) : super(context,null){

        if(id == 0){
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_1, this, true)
        }else if (id == 1){
            dateStyle = "yyyy/MM/dd"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_2, this, true)
        }else if (id == 2){
            dateStyle = "yyyy/\nMM/dd"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_3, this, true)
        }else if (id == 3){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_4, this, true)
        }else if (id == 4){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_5, this, true)
        }else if (id == 5){
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_6, this, true)
        }else if (id == 6){
            dateStyle = "yyyy-MM-dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_7, this, true)
        }else if (id == 7){
            customTextColor = ContextCompat.getColor(context!!,R.color.color_333333)
            dateStyle = "yyyy/MM/dd EEEE"
            LayoutInflater.from(context).inflate(R.layout.item_mask_kao_qin_8, this, true)
        }
        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView()

    }

    private fun initView(){
        location = findViewById(R.id.tv_kao_qin_location)
        remark = findViewById(R.id.tv_kao_qin_remark)
        date = findViewById(R.id.tv_kao_qin_date)
        week = findViewById(R.id.tv_kao_qin_week)
        time = findViewById(R.id.tv_kao_qin_time)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)

        location?.text = MaskConfig.maskLocation

        changeDateTime()


        MaskConfig.maskMap[0]?.forEach {
            if(it.title == "备注"){
                remark?.text = "${it.title}:${it.content}"
                remark?.visibility = if(it.isOpen) View.VISIBLE else View.GONE
            }
        }

        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(customTextColor)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }
    }

}